#include <iostream>
#define LL long long
using namespace std;

const int kMaxN = 1e6 + 10;
const int kMaxM = 1e6 + 10;

struct Order {
  int d, s, t;
} orders[kMaxM];

LL r[kMaxN], diff[kMaxN];

bool Check(int n, int t) {
  fill(diff, diff + n + 2, 0);
  for (int i = 0; i < t; i++) {
    diff[orders[i].s] += orders[i].d;
    diff[orders[i].t + 1] -= orders[i].d;
  }

  LL tmp = 0;
  for (int i = 1; i <= n; i++) {
    tmp += diff[i];
    if (r[i] < tmp) {
      return false;
    }
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> orders[i].d >> orders[i].s >> orders[i].t;
  }
  if (Check(n, m)) {
    cout << "0\n";
  } else {
    int ll = 1, rr = m;

    while (ll < rr) {
      int mm = (ll + rr) >> 1;

      if (!Check(n, mm)) {
        rr = mm;
      } else {
        ll = mm + 1;
      }
    }
    cout << "-1\n"
         << ll << "\n";
  }
  return 0;
}